{_} = require('underscore')

page_yhyqr = (state={},action)->
  switch action.type
    when 'YHYQR/GET_LIST_START'
      Object.assign {},state,{isLoading:true}
    when 'YHYQR/GET_LIST_COMPLETED'
      Object.assign {},state,
        list:action.payload.list
        isLoading:false
        completed:true
    when 'YHYQR/REFRESH_LIST_START'
      Object.assign {},state,{
        list:[]
        isLoading:false
        refreshing:true
      }
    when 'YHYQR/REFRESH_LIST_COMPLETED'
      Object.assign {},state,{
        list:action.payload.list
        isLoading:false
        refreshing:false
        lastFetchTime:action.payload.lastFetchTime
        completed:true
      }
    when 'YHYQR/PILOT_CONFIRM_COMPLETED'
      list = [].concat(state.list)
      debugger
      cur = _.findWhere list,{CHDYNPLANID:action.payload.planid}
      cur.CHPILOTCALLFLAG = '1'
      Object.assign {},state,
        list:list
    when 'YHYQR/PILOT_CONFIRM_FAIL'
      state
    when 'YHYQR/PILOT_CANCEL_COMPLTED'
      debugger
      list = [].concat(state.list)
      cur = _.findWhere list,{CHDYNPLANID:action.payload.planid}
      cur.CHPILOTCALLFLAG = '0'

      Object.assign {},state,
        list:list
    else
      state

module.exports = page_yhyqr
